<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>西瓜后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/autority_management.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/eleTree.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色类别</label>
                    <div class="layui-input-inline">
                        <input type="text" name="roleClass" value="平台管理员" class="layui-input layui_border_none layui-bg-gray" readonly>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色名称</label>
                    <div class="layui-input-inline">
                       <input type="text" class="layui-input" name="roleName">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">请分配权限</label>
                    <div class="layui-input-block">
                        <div class="eleTree ele1" lay-filter="data1"></div>
                    </div>
                    <div class="layui-input-block">
                        <button class="layui-btn layui-bg-blue">获取分配权限选中数据</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/'
    }).extend({
        index: 'lib/index', //主入口模块
        list: 'car_authority_management/list', //list模块
        eleTree: 'car_authority_management/eleTree'
    }).use(['index','list','jquery','eleTree'], function(){
        var $ = layui.jquery;
        var eleTree = layui.eleTree;
        var data1=[
            {
                "label": "车源查询",
                "spread": true,
                "children": [
                    {
                        "label": "用户注册",
                        "spread": true,
                        "disabled": true
                    },
                    {
                        "label": "用户分析",
                        "children": [
                            {
                                "label": "aaaa1",
                                "checked": true
                            }
                        ]
                    },
                    {
                        "label": "整体分析"
                    },
                    {
                        "label": "事件分析"
                    }
                ]
            },
            {
                "label": "采购管理",
                "children": [
                    {
                        "label": "aa1",
                        "disabled": true
                    },
                    {
                        "label": "bb1",
                        "checked": true
                    }
                ]
            },
            {
                "label": "库存管理",
                "children": [
                    {
                        "label": "aa1"
                    },
                    {
                        "label": "bb1"
                    }
                ]
            },
            {
                "label": "线索管理",
                "children": [
                    {
                        "label": "aa1"
                    },
                    {
                        "label": "bb1"
                    }
                ]
            },
            {
                "label": "零售订单管理",
                "children": [
                    {
                        "label": "aa1"
                    },
                    {
                        "label": "bb1"
                    }
                ]
            },
            {
                "label": "门店管理",
                "children": [
                    {
                        "label": "aa1"
                    },
                    {
                        "label": "bb1"
                    }
                ]
            },
            {
                "label": "App基础管理",
                "children": [
                    {
                        "label": "aa1"
                    },
                    {
                        "label": "bb1"
                    }
                ]
            },
            {
                "label": "权限管理",
                "children": [
                    {
                        "label": "aa1"
                    },
                    {
                        "label": "bb1"
                    }
                ]
            }
        ];
        eleTree.render({
            elem: '.ele1',
            // url: "../../data/home/tree.json",
            // type: "post",
            data: data1,
            showCheckbox: true,
            contextmenuList: ["copy","add","edit","remove"],
            drag: true,
            accordion: true
        });
        //分配权限相关事件,根据需求选择使用
        eleTree.on("add(data1)",function(data) {
            console.log(data);
            // 若后台修改，则重新获取后台数据，然后重载
            // eleTree.reload(".ele1", {where: {data: JSON.stringify(data.data)}})
        })
        eleTree.on("edit(data1)",function(data) {
            console.log(data);
        })
        eleTree.on("remove(data1)",function(data) {
            console.log(data);
        })
        eleTree.on("toggleSlide(data1)",function(data) {
            console.log(data);
        })
        eleTree.on("checkbox(data1)",function(data) {
            console.log(data);
        })
        eleTree.on("drag(data1)",function(data) {
            console.log(data);
        })
        //点击获取选中数据
        $(".layui-btn").on("click",function() {
            console.log(eleTree.checkedData(".ele1"));
        })

    });
</script>

</body>
</html>